﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace Rich4Editor
{
    public partial class EditPanel : Form
    {
        public EditPanel()
        {
            InitializeComponent();
        }

        private void EditPanel_Load(object sender, EventArgs e)
        {
            String[] allCards = { "均富卡", "均贫卡", "购地卡", "换地卡", "换屋卡", "转向卡", "改建卡", "拍卖卡", "天使卡", "恶魔卡", "怪兽卡", "拆除卡", "抢夺卡", "停留卡", "冬眠卡", "梦游卡", "陷害卡", "复仇卡", "嫁祸卡", "免费卡", "免罪卡", "送神符", "请神符", "红卡", "黑卡", "查税卡", "涨价卡", "查封卡", "同盟卡", "乌龟卡"};

            for (int i = 0; i < allCards.Length; i++)
            {
                listBox2.Items.Add(allCards[i]);
            }
        }

        public void setCurrency(String txt)
        {
            textBox1.Text = txt;
        }

        public int getCurrency()
        {
            return getIntFrom(textBox1.Text);
        }

        public void setDeposit(String txt)
        {
            textBox2.Text = txt;
        }

        public int getDeposit()
        {
            return getIntFrom(textBox2.Text);
        }

        public void setDot(String txt)
        {
            textBox3.Text = txt;
        }

        public int getDot()
        {
            return getIntFrom(textBox3.Text);
        }

        public void setDaoju(Daoju daoju)
        {
            int[] arr = daoju.getPoints();

            textBox4.Text = arr[0].ToString();
            textBox5.Text = arr[1].ToString();
            textBox6.Text = arr[2].ToString();
            textBox7.Text = arr[3].ToString();
            textBox8.Text = arr[4].ToString();
            textBox9.Text = arr[5].ToString();
            textBox10.Text = arr[6].ToString();
            textBox11.Text = arr[7].ToString();
            textBox12.Text = arr[8].ToString();
            textBox13.Text = arr[9].ToString();
            textBox14.Text = arr[10].ToString();
            textBox15.Text = arr[11].ToString();
            textBox16.Text = arr[12].ToString();
        }

        public int[] getDaoju()
        {
            int[] arr = new int[13];

            arr[0] = getIntFrom(textBox4.Text);
            arr[1] = getIntFrom(textBox5.Text);
            arr[2] = getIntFrom(textBox6.Text);
            arr[3] = getIntFrom(textBox7.Text);
            arr[4] = getIntFrom(textBox8.Text);
            arr[5] = getIntFrom(textBox9.Text);
            arr[6] = getIntFrom(textBox10.Text);
            arr[7] = getIntFrom(textBox11.Text);
            arr[8] = getIntFrom(textBox12.Text);
            arr[9] = getIntFrom(textBox13.Text);
            arr[10] = getIntFrom(textBox14.Text);
            arr[11] = getIntFrom(textBox15.Text);
            arr[12] = getIntFrom(textBox16.Text);

            return arr;
        }

        /// <summary>
        /// 防止转化时出错用的
        /// </summary>
        /// <param name="txt"></param>
        /// <returns></returns>
        private int getIntFrom(String txt)
        {
            int retval = 0;
            try
            {
                retval = Convert.ToInt32(txt);
                return retval;
            }catch(Exception e){
                return 0;
            }
        }

        public void setCard(Card card)
        {
            String[] arr = card.getCardNameArray();

            // 显示
            for (int i = 0; i < arr.Length;i++ )
            {
                if (arr[i].Trim().Length>0)
                {
                    listBox1.Items.Add(arr[i]);
                }                
            }
        }

        /// <summary>
        /// 取得现有卡片
        /// </summary>
        public String[] getCards()
        {
            String[] arr = new String[15];
            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = "";
            }

            for (int i = 0; i < listBox1.Items.Count && i<15; i++)
            {
                string item = listBox1.Items[i].ToString();
                arr[i] = item;
            }

            return arr;
        }

        // 清空
        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
        }

        // 删除当前项
        private void button2_Click(object sender, EventArgs e)
        {
            int index = listBox1.SelectedIndex;

            if (index>-1)
            {
                listBox1.Items.RemoveAt(index);
            }
        }

        // 添加一项
        private void button3_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedItem!=null)
            {
                String item = listBox2.SelectedItem.ToString();
                listBox1.Items.Add(item);
            }           
        }

        // 一次添加十五项
        private void button4_Click(object sender, EventArgs e)
        {
            String[] allCards = { "购地卡", "换地卡", "换屋卡", "转向卡", "天使卡", "抢夺卡", "停留卡", "梦游卡", "嫁祸卡", "免罪卡", "送神符", "请神符", "红卡","查税卡", "乌龟卡" };

            for (int i = 0; i < allCards.Length; i++)
            {
                listBox1.Items.Add(allCards[i]);
            }
        }

        public Boolean check()
        {
            // 现金检查
            String txt = textBox1.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox1.Focus();
                textBox1.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox1.BackColor = Color.White;
            }

            int val = Convert.ToInt32(txt);
            if (val>10000000)
            {
                MessageBox.Show("现金最好小于10000000");
                textBox1.Focus();
                textBox1.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox1.BackColor = Color.White;
            }

            // 存款检查
            txt = textBox2.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox2.Focus();
                textBox2.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox2.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 10000000)
            {
                MessageBox.Show("存款最好小于10000000");
                textBox2.Focus();
                textBox2.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox2.BackColor = Color.White;
            }

            // 点券检查
            txt = textBox3.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox3.Focus();
                textBox3.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox3.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 60000)
            {
                MessageBox.Show("点券最好小于60000");
                textBox3.Focus();
                textBox3.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox3.BackColor = Color.White;
            }

            // 道具检查 1
            txt = textBox4.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox4.Focus();
                textBox4.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox4.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 255)
            {
                MessageBox.Show("道具个数不能大于255");
                textBox4.Focus();
                textBox4.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox4.BackColor = Color.White;
            }

            // 道具检查 2
            txt = textBox5.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox5.Focus();
                textBox5.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox5.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 255)
            {
                MessageBox.Show("道具个数不能大于255");
                textBox5.Focus();
                textBox5.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox5.BackColor = Color.White;
            }

            // 道具检查 3
            txt = textBox6.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox6.Focus();
                textBox6.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox6.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 255)
            {
                MessageBox.Show("道具个数不能大于255");
                textBox6.Focus();
                textBox6.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox6.BackColor = Color.White;
            }

            // 道具检查 7
            txt = textBox7.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox7.Focus();
                textBox7.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox7.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 255)
            {
                MessageBox.Show("道具个数不能大于255");
                textBox7.Focus();
                textBox7.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox7.BackColor = Color.White;
            }

            // 道具检查 8
            txt = textBox8.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox8.Focus();
                textBox8.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox8.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 255)
            {
                MessageBox.Show("道具个数不能大于255");
                textBox8.Focus();
                textBox8.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox8.BackColor = Color.White;
            }

            // 道具检查 9
            txt = textBox9.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox9.Focus();
                textBox9.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox9.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 255)
            {
                MessageBox.Show("道具个数不能大于255");
                textBox9.Focus();
                textBox9.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox9.BackColor = Color.White;
            }

            // 道具检查 10
            txt = textBox10.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox10.Focus();
                textBox10.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox10.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 255)
            {
                MessageBox.Show("道具个数不能大于255");
                textBox10.Focus();
                textBox10.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox10.BackColor = Color.White;
            }

            // 道具检查 11
            txt = textBox11.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox11.Focus();
                textBox11.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox11.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 255)
            {
                MessageBox.Show("道具个数不能大于255");
                textBox11.Focus();
                textBox11.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox11.BackColor = Color.White;
            }

            // 道具检查 12
            txt = textBox12.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox12.Focus();
                textBox12.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox12.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 255)
            {
                MessageBox.Show("道具个数不能大于255");
                textBox12.Focus();
                textBox12.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox12.BackColor = Color.White;
            }

            // 道具检查 13
            txt = textBox13.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox13.Focus();
                textBox13.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox13.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 255)
            {
                MessageBox.Show("道具个数不能大于255");
                textBox13.Focus();
                textBox13.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox13.BackColor = Color.White;
            }

            // 道具检查 14
            txt = textBox14.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox14.Focus();
                textBox14.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox14.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 255)
            {
                MessageBox.Show("道具个数不能大于255");
                textBox14.Focus();
                textBox14.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox14.BackColor = Color.White;
            }

            // 道具检查 15
            txt = textBox15.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox15.Focus();
                textBox15.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox15.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 255)
            {
                MessageBox.Show("道具个数不能大于255");
                textBox15.Focus();
                textBox15.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox15.BackColor = Color.White;
            }

            // 道具检查 16
            txt = textBox16.Text;
            if (IsInt(txt) == false)
            {
                MessageBox.Show("请输入数字");
                textBox16.Focus();
                textBox16.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox16.BackColor = Color.White;
            }

            val = Convert.ToInt32(txt);
            if (val > 255)
            {
                MessageBox.Show("道具个数不能大于255");
                textBox16.Focus();
                textBox16.BackColor = Color.Red;

                return false;
            }
            else
            {
                textBox16.BackColor = Color.White;
            }



            return true;
        }

        public static bool IsNumeric(string value)
        {
            return Regex.IsMatch(value, @"^[+-]?\d*[.]?\d*$");
        }
        public static bool IsInt(string value)
        {
            return Regex.IsMatch(value, @"^[+-]?\d*$");
        }
        public static bool IsUnsign(string value)
        {
            return Regex.IsMatch(value, @"^\d*[.]?\d*$");
        }

        public static bool isTel(string strInput)
        {
            return Regex.IsMatch(strInput, @"\d{3}-\d{8}|\d{4}-\d{7}");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            textBox4.Text = "255";
            textBox5.Text = "255";
            textBox6.Text = "255";
            textBox7.Text = "255";
            textBox8.Text = "255";
            textBox9.Text = "255";
            textBox10.Text = "255";
            textBox11.Text = "255";
            textBox12.Text = "255";
            textBox13.Text = "255";
            textBox14.Text = "255";
            textBox15.Text = "255";
            textBox16.Text = "255";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            textBox4.Text = "0";
            textBox5.Text = "0";
            textBox6.Text = "0";
            textBox7.Text = "0";
            textBox8.Text = "0";
            textBox9.Text = "0";
            textBox10.Text = "0";
            textBox11.Text = "0";
            textBox12.Text = "0";
            textBox13.Text = "0";
            textBox14.Text = "0";
            textBox15.Text = "0";
            textBox16.Text = "0";
        }
    }
}
